package com.zhuang.controller;


import com.zhuang.pojo.User;
import com.zhuang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author KangXiaoZhuang
 * @since 2021-10-23
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/findOne/{id}")
    public User findOne(@PathVariable Integer id) {
        return userService.getById(id);
    }

    @RequestMapping("/all")
    public List<User> getAll() {
        return userService.list();
    }

    @PostMapping("/addUser")
    public boolean addUser(@RequestBody User user) {
        return userService.save(user);
    }

    @DeleteMapping("/deleteUser/{id}")
    public boolean deleteUser(@PathVariable Integer id) {
        return userService.removeById(id);
    }

    @PutMapping("/updateUser")
    public boolean update(@RequestBody User user) {
        return userService.updateById(user);
    }
}

